//
//  HZBaseTableViewController.m
//  微博 OC
//
//  Created by 黑眼圈 on 16/4/18.
//  Copyright © 2016年 heiyan. All rights reserved.
//

#import "HZBaseTableViewController.h"
#import "HZLoginView.h"
#import "HZOAuthVc.h"
#import "HZOAuthVM.h"

@interface HZBaseTableViewController ()



@end


@implementation HZBaseTableViewController

-(void)loadView{
    
    self.logined = [[HZOAuthVM sharedOAuth] isslogined];
    
    if (self.logined!=0) {
        
        [super loadView];
        return;
    }
    
    HZLoginView* logView = [[HZLoginView alloc]init];
    
    
    self.view = logView;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
  //接收通知
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(login) name:@"login" object:nil];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(registered) name:@"register" object:nil];
    
    
    //添加导航条的子控件
    [self setupUI];
    
    
    //如果登录了就销毁注册和登录按钮
    if ([[HZOAuthVM sharedOAuth] isslogined]) {
        
        self.navigationItem.leftBarButtonItem = nil;
        self.navigationItem.rightBarButtonItem = nil;
    }
}


#pragma mark -
#pragma mark    添加导航条的子控件
-(void)setupUI{
    
    UIBarButtonItem* registerBar = [[UIBarButtonItem alloc]initWithTitle:@"注册" style:UIBarButtonItemStylePlain target:self action:@selector(registered)];
    
    UIBarButtonItem* loginBar = [[UIBarButtonItem alloc]initWithTitle:@"登录" style:UIBarButtonItemStylePlain target:self action:@selector(login)];
    
    self.navigationItem.leftBarButtonItem =registerBar;
    self.navigationItem.rightBarButtonItem = loginBar;
}



#pragma mark -
#pragma mark     实现通知方法
-(void)login{
    
//    NSLog(@"登录了");
    HZOAuthVc* oauthVc = [[HZOAuthVc alloc]init];
    
    
    [self presentViewController:[[UINavigationController alloc]initWithRootViewController:oauthVc] animated:YES completion:nil];
    
}

-(void)registered{
    
     NSLog(@"注册了");
}















@end
